<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register</title>
<script src="../static/js/jquery-3.3.1.js" type="text/javascript"></script>
<script src="../static/js/md5.js" type="text/javascript"></script>
</head>
<body>
	<form action="/register" method="post" onsubmit="encrypt()">
		用户名：<input type="text" id="username" name="username"
			/><span class="msg"></span><br /> 密码：<input
			type="password" id = "password" name="password"  /><br />
		年龄：<input type="text" name="age" /><br /> 兴趣：<input type="checkbox"
			name="hobby" value="运动 " />运动 <input type="checkbox" name="hobby"
			value="读书" />读书 <input type="checkbox" name="hobby" value="旅游 " />旅游
		<input type="checkbox" name="hobby" value="健身" />健身<br /> 地址：<input
			type="text" name="address" /><br /> 头像：<input
			type="file" name="img"  /><br /> <input
			type="hidden" name="method" value="addUser" /><br /> <input
			type="submit" value="注册">
	</form>
	<script>
		function encrypt() {
			/* 加盐 使md5更健壮这个最好是从服务端动态获取 */
			var salt = "!@#$%^&*()_+";
			var pass = $("#password").val();
			pass = hex_md5(pass+salt);
			pass = hex_md5(pass+salt);
			$("#password").val(pass);
		}

		$("#username").change(function() {
			var username = $(this).val();
			$.ajax({
				url : "/check",
				data : {
					username : username
				},
				async : true,//默认
				type : "post",
				dataType : "text",
				success : function(data) {
					$(".msg").html(data);
				},
				error : function(a) {
					alert(a);
				}
			})

		})
	</script>

</body>
</html>